<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>EDS API: ArchClient.cpp</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="logo.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">EDS API
   </div>
   <div id="projectbrief">Enterprise Data Server Application Programming Interface</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.1.2 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('_arch_client_8cpp-example.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Pages</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">ArchClient.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><span class="preprocessor">#ifdef WIN32</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#include &lt;windows.h&gt;</span></div>
<div class="line"><span class="preprocessor">#endif</span></div>
<div class="line"><span class="preprocessor"></span></div>
<div class="line"><span class="preprocessor">#include &lt;stdio.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;stdlib.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;time.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;memory&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="comment">// EDS LiveClient header file</span></div>
<div class="line"><span class="preprocessor">#include &quot;../include/LiveClient.h&quot;</span></div>
<div class="line"></div>
<div class="line"><span class="comment">// EDS ArchClient header file</span></div>
<div class="line"><span class="preprocessor">#include &quot;../include/ArchClient.h&quot;</span></div>
<div class="line"></div>
<div class="line"><span class="comment">// Some common types are defined in eds namespace</span></div>
<div class="line"><span class="keyword">using namespace </span>eds;</div>
<div class="line"><span class="comment">// LiveClient is in eds::live namespace</span></div>
<div class="line"><span class="keyword">using namespace </span>eds::live;</div>
<div class="line"><span class="comment">// ArchClient is in eds::arch namespace</span></div>
<div class="line"><span class="keyword">using namespace </span>eds::arch;</div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><a name="_a0"></a><a class="code" href="classeds_1_1live_1_1_live_client.html" title="Live data client.">LiveClient</a>* initializeLiveClient(<span class="keyword">const</span> <span class="keywordtype">char</span>* version,</div>
<div class="line">                                 <span class="keyword">const</span> <span class="keywordtype">char</span>* host,</div>
<div class="line">                                 <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> port)</div>
<div class="line">{</div>
<div class="line">  <span class="keywordflow">try</span></div>
<div class="line">  {</div>
<div class="line">    printf(<span class="stringliteral">&quot;Creating LiveClient for EDS version %s...\n&quot;</span>, version);</div>
<div class="line">    std::auto_ptr&lt;LiveClient&gt; client(<span class="keyword">new</span> <a class="code" href="classeds_1_1live_1_1_live_client.html" title="Live data client.">LiveClient</a>(version));</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Initialize in read mode</span></div>
<div class="line">    printf(<span class="stringliteral">&quot;Initializing LiveClient connection to %s:%u...\n&quot;</span>, host, port);</div>
<div class="line">    client-&gt;<a name="a1"></a><a class="code" href="classeds_1_1live_1_1_live_client.html#a5875940c5ff34b50a6ac621c88fa8ffc" title="Initializes connection to a live server.">init</a>(AccessMode_Read,</div>
<div class="line">                 <span class="stringliteral">&quot;0.0.0.0&quot;</span>,       <span class="comment">// bind to all local interfaces</span></div>
<div class="line">                 0,               <span class="comment">// bind to any local port</span></div>
<div class="line">                 host,</div>
<div class="line">                 port,</div>
<div class="line">                 50);</div>
<div class="line"></div>
<div class="line">    printf(<span class="stringliteral">&quot;LiveClient initialized successfully!\n&quot;</span>);</div>
<div class="line">    <span class="keywordflow">return</span> client.release();</div>
<div class="line">  }</div>
<div class="line">  <span class="keywordflow">catch</span> (<span class="keyword">const</span> <a name="_a2"></a><a class="code" href="classeds_1_1_backend_not_found_error.html" title="Backend not found exception class.">BackendNotFoundError</a>&amp; exc)</div>
<div class="line">  {</div>
<div class="line">    <span class="comment">// Couldn&#39;t load backend. Requested version might be incorrect,</span></div>
<div class="line">    <span class="comment">// or &#39;edsapi_live_*&#39; library might be missing.</span></div>
<div class="line">    printf(<span class="stringliteral">&quot;Couldn&#39;t load live backend library for EDS %s (%s)\n&quot;</span>,</div>
<div class="line">      version, exc.what());</div>
<div class="line">    <span class="keywordflow">return</span> 0;</div>
<div class="line">  }</div>
<div class="line">  <span class="keywordflow">catch</span> (<span class="keyword">const</span> <a name="_a3"></a><a class="code" href="classeds_1_1live_1_1_live_client_error.html" title="Thrown when backend library returns an error.">LiveClientError</a>&amp; exc)</div>
<div class="line">  {</div>
<div class="line">    printf(<span class="stringliteral">&quot;Couldn&#39;t initialize live client connection object (%s)\n&quot;</span>,</div>
<div class="line">      exc.what());</div>
<div class="line">    <span class="keywordflow">return</span> 0;</div>
<div class="line">  }</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> sidFromPointName(<a class="code" href="classeds_1_1live_1_1_live_client.html" title="Live data client.">LiveClient</a>* client, <span class="keyword">const</span> <span class="keywordtype">char</span>* pointName)</div>
<div class="line">{</div>
<div class="line">  <span class="keywordflow">try</span></div>
<div class="line">  {</div>
<div class="line">    <span class="keywordtype">int</span> lid = client-&gt;<a name="a4"></a><a class="code" href="classeds_1_1live_1_1_live_client.html#abcc332d091d41c17046a6fb6c0f5d117" title="Returns local id of point identified by IESS.">findByIESS</a>(pointName);</div>
<div class="line">    <span class="keywordflow">if</span> (lid == -1)</div>
<div class="line">    {</div>
<div class="line">      printf(<span class="stringliteral">&quot;Couldn&#39;t find point with IESS &#39;%s&#39;\n&quot;</span>, pointName);</div>
<div class="line">      <span class="keywordflow">return</span> -1;</div>
<div class="line">    }</div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">return</span> client-&gt;<a name="a5"></a><a class="code" href="classeds_1_1live_1_1_live_client.html#a3d9c9f50ca89e68c16843d298e85ace3" title="Returns server identifier of point.">pointSID</a>(lid);</div>
<div class="line">  }</div>
<div class="line">  <span class="keywordflow">catch</span> (<span class="keyword">const</span> <a name="_a6"></a><a class="code" href="classeds_1_1_error.html" title="Base exception class.">Error</a>&amp; exc)</div>
<div class="line">  {</div>
<div class="line">    printf(<span class="stringliteral">&quot;Failed to resolve server id from point name &#39;%s&#39; (%s)\n&quot;</span>,</div>
<div class="line">      pointName, exc.what());</div>
<div class="line">    <span class="keywordflow">return</span> -1;</div>
<div class="line">  }</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><a name="_a7"></a><a class="code" href="classeds_1_1arch_1_1_arch_client.html" title="Archive data client.">ArchClient</a>* initializeArchClient(<span class="keyword">const</span> <span class="keywordtype">char</span>* version,</div>
<div class="line">                                 <span class="keyword">const</span> <span class="keywordtype">char</span>* host,</div>
<div class="line">                                 <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> port)</div>
<div class="line">{</div>
<div class="line">  <span class="keywordflow">try</span></div>
<div class="line">  {</div>
<div class="line">    printf(<span class="stringliteral">&quot;Creating ArchClient for EDS version %s...\n&quot;</span>, version);</div>
<div class="line">    std::auto_ptr&lt;ArchClient&gt; client(<span class="keyword">new</span> <a class="code" href="classeds_1_1arch_1_1_arch_client.html" title="Archive data client.">ArchClient</a>(version));</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Initialize as client (read mode)</span></div>
<div class="line">    printf(<span class="stringliteral">&quot;Initializing ArchClient connection to %s:%u...\n&quot;</span>, host, port);</div>
<div class="line">    client-&gt;<a class="code" href="classeds_1_1live_1_1_live_client.html#a5875940c5ff34b50a6ac621c88fa8ffc" title="Initializes connection to a live server.">init</a>(<span class="stringliteral">&quot;0.0.0.0&quot;</span>, <span class="comment">// bind to all local interfaces</span></div>
<div class="line">                 0,         <span class="comment">// bind to any local port</span></div>
<div class="line">                 host,</div>
<div class="line">                 port,</div>
<div class="line">                 50);</div>
<div class="line"></div>
<div class="line">    printf(<span class="stringliteral">&quot;ArchClient initialized successfully!\n&quot;</span>);</div>
<div class="line">    <span class="keywordflow">return</span> client.release();</div>
<div class="line">  }</div>
<div class="line">  <span class="keywordflow">catch</span> (<span class="keyword">const</span> <a class="code" href="classeds_1_1_backend_not_found_error.html" title="Backend not found exception class.">BackendNotFoundError</a>&amp; exc)</div>
<div class="line">  {</div>
<div class="line">    <span class="comment">// Couldn&#39;t load backend. Requested version might be incorrect,</span></div>
<div class="line">    <span class="comment">// or &#39;edsapi_arch_*&#39; library might be missing.</span></div>
<div class="line">    printf(<span class="stringliteral">&quot;Couldn&#39;t load arch backend library for EDS %s (%s)\n&quot;</span>,</div>
<div class="line">      version, exc.what());</div>
<div class="line">    <span class="keywordflow">return</span> 0;</div>
<div class="line">  }</div>
<div class="line">  <span class="keywordflow">catch</span> (<span class="keyword">const</span> <a name="_a8"></a><a class="code" href="classeds_1_1arch_1_1_arch_client_error.html" title="Thrown when backend library returns an error.">ArchClientError</a>&amp; exc)</div>
<div class="line">  {</div>
<div class="line">    printf(<span class="stringliteral">&quot;Couldn&#39;t initialize arch client connection object (%s)\n&quot;</span>,</div>
<div class="line">      exc.what());</div>
<div class="line">    <span class="keywordflow">return</span> 0;</div>
<div class="line">  }</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">void</span> executeReports(<a class="code" href="classeds_1_1arch_1_1_arch_client.html" title="Archive data client.">ArchClient</a>* client, <span class="keywordtype">int</span> maxSid, <span class="keywordtype">int</span> avgSid)</div>
<div class="line">{</div>
<div class="line">  <span class="keywordflow">try</span></div>
<div class="line">  {</div>
<div class="line">    printf(<span class="stringliteral">&quot;Executing reports...\n&quot;</span>);</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Pointers are wrapped in auto_ptr to automatically release objects</span></div>
<div class="line">    <span class="comment">// in case of exception.</span></div>
<div class="line">    std::auto_ptr&lt;ReportFunction&gt; maxFunction(</div>
<div class="line">      client-&gt;<a name="a9"></a><a class="code" href="classeds_1_1arch_1_1_arch_client.html#a3045813bcff66347f010d790c6a1f992" title="Creates a ReportFunction object for a specific raw or aggregate Archive Server function.">getReportFunction</a>(<span class="stringliteral">&quot;MAX_VALUE&quot;</span>));</div>
<div class="line">    std::auto_ptr&lt;ReportFunction&gt; avgFunction(</div>
<div class="line">      client-&gt;<a class="code" href="classeds_1_1arch_1_1_arch_client.html#a3045813bcff66347f010d790c6a1f992" title="Creates a ReportFunction object for a specific raw or aggregate Archive Server function.">getReportFunction</a>(<span class="stringliteral">&quot;AVG&quot;</span>));</div>
<div class="line"></div>
<div class="line">    time_t now = time(0);</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Calculate maximum for point maxSid over last 24 hours.</span></div>
<div class="line">    maxFunction-&gt;pushPointParam(maxSid);</div>
<div class="line">    maxFunction-&gt;pushTimestampParam(now - 24 * 3600);</div>
<div class="line">    maxFunction-&gt;pushTimestampParam(now);</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Calculate average for point avgSid over last 24 hours.</span></div>
<div class="line">    <span class="comment">// Shades will have priority over values from archive.</span></div>
<div class="line">    avgFunction-&gt;pushPointParam(avgSid, 0xFF, <a name="a10"></a><a class="code" href="namespaceeds_1_1arch.html#a32e2fe0d83ab8f76bae8606995802373a4703a549f726f1c3d78937b20d4dce17" title="Prefer shades over archive values.">ShadeMode_PreferShade</a>);</div>
<div class="line">    avgFunction-&gt;pushTimestampParam(now - 24 * 3600);</div>
<div class="line">    avgFunction-&gt;pushTimestampParam(now);</div>
<div class="line"></div>
<div class="line">    <span class="keywordtype">int</span> maxQuery = client-&gt;<a name="a11"></a><a class="code" href="classeds_1_1arch_1_1_arch_client.html#a3cb2b8c876b7c2d1496080dbaf712e81" title="Enqueues a report function for execution.">addQuery</a>(maxFunction.get());</div>
<div class="line">    <span class="keywordtype">int</span> avgQuery = client-&gt;<a class="code" href="classeds_1_1arch_1_1_arch_client.html#a3cb2b8c876b7c2d1496080dbaf712e81" title="Enqueues a report function for execution.">addQuery</a>(avgFunction.get());</div>
<div class="line"></div>
<div class="line">    <span class="comment">// This function will block until reports are ready</span></div>
<div class="line">    client-&gt;<a name="a12"></a><a class="code" href="classeds_1_1arch_1_1_arch_client.html#ab4a3dd61df80a139b8790a3a2b600a23" title="Executes all queued report functions.">executeQueries</a>();</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Fetch and display report results</span></div>
<div class="line">    <span class="keywordtype">char</span> quality;</div>
<div class="line"></div>
<div class="line">    printf(<span class="stringliteral">&quot;Report results:\n&quot;</span>);</div>
<div class="line">    <span class="keywordtype">double</span> maxValue = client-&gt;<a name="a13"></a><a class="code" href="classeds_1_1arch_1_1_arch_client.html#ad492c5a85f5026d7e601981269520d93" title="Reads result (value, quality) from given report query id.">getResponse</a>(maxQuery, &amp;quality);</div>
<div class="line">    printf(<span class="stringliteral">&quot;MAX_VALUE(sid=%d) = %f%c\n&quot;</span>, maxSid, maxValue, quality);</div>
<div class="line"></div>
<div class="line">    <span class="keywordtype">double</span> avgValue = client-&gt;<a class="code" href="classeds_1_1arch_1_1_arch_client.html#ad492c5a85f5026d7e601981269520d93" title="Reads result (value, quality) from given report query id.">getResponse</a>(avgQuery, &amp;quality);</div>
<div class="line">    printf(<span class="stringliteral">&quot;AVG(sid=%d) = %f%c\n&quot;</span>, avgSid, avgValue, quality);</div>
<div class="line">  }</div>
<div class="line">  <span class="keywordflow">catch</span> (<span class="keyword">const</span> <a class="code" href="classeds_1_1_error.html" title="Base exception class.">Error</a>&amp; exc)</div>
<div class="line">  {</div>
<div class="line">    printf(<span class="stringliteral">&quot;Failed to execute report functions (%s)\n&quot;</span>, exc.what());</div>
<div class="line">  }</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">void</span> writeShades(<a class="code" href="classeds_1_1arch_1_1_arch_client.html" title="Archive data client.">ArchClient</a>* client, <span class="keywordtype">int</span> sid1, <span class="keywordtype">int</span> sid2)</div>
<div class="line">{</div>
<div class="line">  <span class="keywordflow">try</span></div>
<div class="line">  {</div>
<div class="line">    printf(<span class="stringliteral">&quot;Writing shades...\n&quot;</span>);</div>
<div class="line"></div>
<div class="line">    time_t now = time(0);</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Write 10.0G for last 5 hours</span></div>
<div class="line">    client-&gt;<a name="a14"></a><a class="code" href="classeds_1_1arch_1_1_arch_client.html#ad77604a1935e3570802ce3e29ee48969" title="Enqueues a shade to be written.">addShadeValue</a>(sid1,</div>
<div class="line">                          now - 5 * 3600,</div>
<div class="line">                          now,</div>
<div class="line">                          10.0,</div>
<div class="line">                          Quality_Good);</div>
<div class="line">    <span class="comment">// Write 20.0G for range &lt;-5 hours; -2 hours&gt;</span></div>
<div class="line">    client-&gt;<a class="code" href="classeds_1_1arch_1_1_arch_client.html#ad77604a1935e3570802ce3e29ee48969" title="Enqueues a shade to be written.">addShadeValue</a>(sid2,</div>
<div class="line">                          now - 5 * 3600,</div>
<div class="line">                          now - 2 * 3600 - 1,</div>
<div class="line">                          20.0,</div>
<div class="line">                          Quality_Good);</div>
<div class="line">    <span class="comment">// Write 40.0 for range &lt;-2 hours; +5 hours&gt;</span></div>
<div class="line">    client-&gt;<a class="code" href="classeds_1_1arch_1_1_arch_client.html#ad77604a1935e3570802ce3e29ee48969" title="Enqueues a shade to be written.">addShadeValue</a>(sid2,</div>
<div class="line">                          now - 2 * 3600,</div>
<div class="line">                          now + 5 * 3600,</div>
<div class="line">                          40.0,</div>
<div class="line">                          Quality_Good);</div>
<div class="line"></div>
<div class="line">    <span class="comment">// This function will block while shades are written</span></div>
<div class="line">    client-&gt;<a name="a15"></a><a class="code" href="classeds_1_1arch_1_1_arch_client.html#a4b4bd14fe7ae649f86693357f9d3a0d1" title="Writes all queued shades.">writeShades</a>();</div>
<div class="line"></div>
<div class="line">    printf(<span class="stringliteral">&quot;Shades written successfully!\n&quot;</span>);</div>
<div class="line">  }</div>
<div class="line">  <span class="keywordflow">catch</span> (<span class="keyword">const</span> <a class="code" href="classeds_1_1_error.html" title="Base exception class.">Error</a>&amp; exc)</div>
<div class="line">  {</div>
<div class="line">    printf(<span class="stringliteral">&quot;Failed to write shades (%s)\n&quot;</span>, exc.what());</div>
<div class="line">  }</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">void</span> executeTabularTrends(<a class="code" href="classeds_1_1arch_1_1_arch_client.html" title="Archive data client.">ArchClient</a>* client, <span class="keywordtype">int</span> valueSid, <span class="keywordtype">int</span> avgSid)</div>
<div class="line">{</div>
<div class="line">  <span class="keywordflow">try</span></div>
<div class="line">  {</div>
<div class="line">    printf(<span class="stringliteral">&quot;Executing tabular trends...\n&quot;</span>);</div>
<div class="line"></div>
<div class="line">    time_t now = time(0);</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Pointers are wrapped in auto_ptr to automatically release objects</span></div>
<div class="line">    <span class="comment">// in case of exception.</span></div>
<div class="line"></div>
<div class="line">    <span class="comment">// Create VALUE trend with preference for shade values over archives</span></div>
<div class="line">    std::auto_ptr&lt;TabularTrend&gt; valueTabTrend(</div>
<div class="line">      client-&gt;<a name="a16"></a><a class="code" href="classeds_1_1arch_1_1_arch_client.html#a744cb3bb325e6b9c2d84cb67a299c6cb" title="Creates a TabularTrend object for a specific point and archive function.">getTabularTrend</a>(valueSid, <span class="stringliteral">&quot;VALUE&quot;</span>));</div>
<div class="line">    client-&gt;<a name="a17"></a><a class="code" href="classeds_1_1arch_1_1_arch_client.html#a6f576744e47f6625350963eedc16c93a" title="Enqueues a tabular trend for execution.">addTabularTrend</a>(valueTabTrend.get(), <a class="code" href="namespaceeds_1_1arch.html#a32e2fe0d83ab8f76bae8606995802373a4703a549f726f1c3d78937b20d4dce17" title="Prefer shades over archive values.">ShadeMode_PreferShade</a>);</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Create AVG trend</span></div>
<div class="line">    std::auto_ptr&lt;TabularTrend&gt; avgTabTrend(</div>
<div class="line">      client-&gt;<a class="code" href="classeds_1_1arch_1_1_arch_client.html#a744cb3bb325e6b9c2d84cb67a299c6cb" title="Creates a TabularTrend object for a specific point and archive function.">getTabularTrend</a>(avgSid, <span class="stringliteral">&quot;AVG&quot;</span>));</div>
<div class="line">    client-&gt;<a class="code" href="classeds_1_1arch_1_1_arch_client.html#a6f576744e47f6625350963eedc16c93a" title="Enqueues a tabular trend for execution.">addTabularTrend</a>(avgTabTrend.get());</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Execute both trends for last 5 hours with 1 hour step size.</span></div>
<div class="line">    <span class="comment">// This function will block until trends are ready.</span></div>
<div class="line">    client-&gt;<a name="a18"></a><a class="code" href="classeds_1_1arch_1_1_arch_client.html#ad5df00ccc3877637c449d2f609ac42ac" title="Executes all queued tabular trends.">executeTabularTrends</a>(now - 5 * 3600, 5 * 3600, 3600);</div>
<div class="line"></div>
<div class="line">    printf(<span class="stringliteral">&quot;Tabular trend results:\n&quot;</span>);</div>
<div class="line">    printf(<span class="stringliteral">&quot;VALUE:      \tAVG:        \n&quot;</span>);</div>
<div class="line">    <a class="code" href="namespaceeds_1_1arch.html#a1401dd12e8bc228f41b1688b4395d55b" title="Row of tabular trend result data.">TabularTrendRow</a> row;</div>
<div class="line">    <span class="keywordflow">while</span> (client-&gt;<a name="a19"></a><a class="code" href="classeds_1_1arch_1_1_arch_client.html#a4a847796aea1483260664dfd30d6c5fc" title="Fetches a row of data from tabular trend and advances to the next row.">fetchTabularTrendRow</a>(&amp;row))</div>
<div class="line">    {</div>
<div class="line">      <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i = 0; i &lt; row.size(); ++i)</div>
<div class="line">        printf(<span class="stringliteral">&quot;%12.6f%c\t&quot;</span>, row[i].value, row[i].quality);</div>
<div class="line">      printf(<span class="stringliteral">&quot;\n&quot;</span>);</div>
<div class="line">    }</div>
<div class="line">  }</div>
<div class="line">  <span class="keywordflow">catch</span> (<span class="keyword">const</span> <a class="code" href="classeds_1_1_error.html" title="Base exception class.">Error</a>&amp; exc)</div>
<div class="line">  {</div>
<div class="line">    printf(<span class="stringliteral">&quot;Failed to write shades (%s)\n&quot;</span>, exc.what());</div>
<div class="line">  }</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>** argv)</div>
<div class="line">{</div>
<div class="line">  <span class="keywordflow">if</span> (argc != 5)</div>
<div class="line">  {</div>
<div class="line">    printf(<span class="stringliteral">&quot;Usage: %s version rhost srv_port archsrv_port\n&quot;</span>, argv[0]);</div>
<div class="line">    <span class="keywordflow">return</span> 1;</div>
<div class="line">  }</div>
<div class="line"></div>
<div class="line">  <span class="keyword">const</span> <span class="keywordtype">char</span>* version = argv[1];</div>
<div class="line">  <span class="keyword">const</span> <span class="keywordtype">char</span>* rhost = argv[2];</div>
<div class="line">  <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> srv_rport = (<span class="keywordtype">unsigned</span> short)atoi(argv[3]);</div>
<div class="line">  <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> archsrv_rport = (<span class="keywordtype">unsigned</span> short)atoi(argv[4]);</div>
<div class="line"></div>
<div class="line">  <span class="comment">// LiveClient is needed only to resolve point names (IESS) to server ids</span></div>
<div class="line">  std::auto_ptr&lt;LiveClient&gt; liveClient(</div>
<div class="line">    initializeLiveClient(version, rhost, srv_rport));</div>
<div class="line">  <span class="keywordflow">if</span> (liveClient.get() == 0)</div>
<div class="line">    <span class="keywordflow">return</span> 2;</div>
<div class="line"></div>
<div class="line">  <span class="keywordtype">int</span> a1Sid = sidFromPointName(liveClient.get(), <span class="stringliteral">&quot;A1&quot;</span>);</div>
<div class="line">  <span class="keywordtype">int</span> a2Sid = sidFromPointName(liveClient.get(), <span class="stringliteral">&quot;A2&quot;</span>);</div>
<div class="line">  <span class="keywordflow">if</span> (a1Sid &lt; 0 || a2Sid &lt; 0)</div>
<div class="line">    <span class="keywordflow">return</span> 3;</div>
<div class="line"></div>
<div class="line">  std::auto_ptr&lt;ArchClient&gt; archClient(</div>
<div class="line">    initializeArchClient(version, rhost, archsrv_rport));</div>
<div class="line">  <span class="keywordflow">if</span> (archClient.get() == 0)</div>
<div class="line">    <span class="keywordflow">return</span> 4;</div>
<div class="line"></div>
<div class="line">  executeReports(archClient.get(), a1Sid, a2Sid);</div>
<div class="line">  writeShades(archClient.get(), a1Sid, a2Sid);</div>
<div class="line">  executeTabularTrends(archClient.get(), a1Sid, a2Sid);</div>
<div class="line"></div>
<div class="line">  <span class="keywordflow">return</span> 0;</div>
<div class="line">}</div>
</div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated on Tue Jul 31 2012 17:22:09 for EDS API by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.1.2 </li>
  </ul>
</div>
</body>
</html>
